package etxt2db.minorthird;
import java.util.List;
import java.util.Set;

import edu.cmu.minorthird.classify.ExampleSchema;
import edu.cmu.minorthird.text.MonotonicTextLabels;
import edu.cmu.minorthird.text.Span;
import edu.cmu.minorthird.text.TextLabels;


public abstract class MultiClassExtraction2TaggingReduction {
	/** Convert the information in a single annotation example to token
	 * 'tags' (token properties, assigned to every token).
	 */
	abstract public void reduceExtraction2Tagging(MultiClassAnnotationExample example);

	/** Return the token property used for the tags which encode the
	 * extraction task.
	 */
	abstract public List<String> getTokenProp();
	
	/** Get all the tag values that were used.
	 */
	abstract public Set<String> getNonDefaultTagValues();

	/** Return the TextLabels holding the tags which encode the
	 * extraction task.
	 */
	abstract public TextLabels getTaggedLabels();

	/** Alter a TextLabels object with tagged tokens by using them to
	 * solve the extraction problem. */
	abstract public void extractFromTags(List<String> output, MonotonicTextLabels labels);

	//
	// convenience methods
	//

	/** Label all tokens as negative, including ones which are inside a
	 * span to be extracted.  This is intended to be used before labeling
	 * the positive tokens appropriately.
	 */
	protected void assignDefaultLabels(Span doc,MonotonicTextLabels taggedLabels,String spanType)
	{
		// use the closed world information
		/*for (Iterator<Span> i=taggedLabels.closureIterator(spanType,doc.getDocumentId()); i.hasNext(); ) {
			Span span = i.next();
			for (int j=0; j<span.size(); j++) {
				for(String tokenProp : getTokenProp()){
					taggedLabels.setProperty( span.getToken(j), spanType, ExampleSchema.NEG_CLASS_NAME );
				}
			}
		}*/
		for (int j=0; j<doc.size(); j++) {
			taggedLabels.setProperty( doc.getToken(j), spanType, ExampleSchema.NEG_CLASS_NAME );
		}
	}
}
